﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Miris.HumanMilkAnalyser.DataModel;

namespace Miris.HumanMilkAnalyser.Service.Validation
{
    public class DiagnosticMessageReferenceValidator : DataValidatorBase<DiagnosticMessageReference>
    {
        public const string MessageContentErrorKey = "MessageContent";

        /// <summary>
        /// Validate the provided entity. Then check the IsValid property to see the result.
        /// </summary>
        /// <param name="entity">The provided entity to be validated.</param>
        public override void Validate(DiagnosticMessageReference entity)
        {
            CheckRequiredMessageContent(entity);
            CheckMessageContentLength(entity);
        }

        /// <summary>
        /// Check if the required message content is provided.
        /// </summary>
        /// <param name="entity">The instance of Patient.</param>
        /// <returns>True means passed. False means failed.</returns>
        public bool CheckRequiredMessageContent(DiagnosticMessageReference entity)
        {
            if (!ValidationHelper.RuleCheckRequiredContent(entity.MessageContent))
            {
                AddError(MessageContentErrorKey, "诊断信息内容不能为空");
                return false;
            }
            else
            {
                return true;
            }
        }

        /// <summary>
        /// Check the message content's max length.
        /// </summary>
        /// <param name="entity">The instance of Patient.</param>
        /// <returns>True means passed. False means failed.</returns>
        public bool CheckMessageContentLength(DiagnosticMessageReference entity)
        {
            int maxLength = 100;

            if (!ValidationHelper.RuleCheckMaxLength(maxLength, entity.MessageContent))
            {
                AddError(MessageContentErrorKey, string.Format("诊断信息内容长度不能超过{0}", maxLength));
                return false;
            }
            else
            {
                return true;
            }
        }
    }
}
